#pragma once

#include<stdio.h>
#include<stdbool.h>
#define STDataType int
#include<assert.h>
#include<stdlib.h>
typedef struct stack
{
    STDataType* a;
    int top;
    int capacity;
}ST;
void STInit(ST* stack)
{

    stack->a = (STDataType*)malloc(sizeof(STDataType) * 4);
    if (stack->a == NULL)
    {
        perror("malloc fail");
        return;
    }
    stack->top = 0;
    stack->capacity = 4;
}
void STPush(ST* stack, STDataType x)
{
    assert(stack);

    if (stack->capacity == stack->top)
    {
        STDataType* tmp = (STDataType*)realloc(stack->a, sizeof(STDataType) * stack->capacity * 2);
        if (!tmp)
        {
            perror("realloc fail");
            return;
        }
        stack->a = tmp;
    }
    stack->a[stack->top++] = x;
}


void STPop(ST* stack)
{
    assert(stack->top);
    stack->top--;
}
void STDestory(ST* stack)
{
    free(stack->a);
    stack->a = NULL;
}
bool STEmptry(ST* stack)
{
    if (stack->top == 0)
        return true;
    return false;
}
STDataType STTop(ST* stack)
{
    return stack->a[stack->top - 1];
}
